/*


 */

package jas.rpc.client;

import jas.rpc.RemoteObject;
import jas.rpc.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

/**
 * Translates <code>RemoteObject</code> objects into corresponding stub objects.
 */
public class RpcClientObjectInputStream extends ObjectInputStream {
    
    private RpcClient client;
    private StubFactory stubFactory;
    
    public RpcClientObjectInputStream(InputStream stream, RpcClient client, StubFactory stubFactory) throws IOException {
        super(stream);
        this.client = client;
        this.stubFactory = stubFactory;
        enableResolveObject(true);
    }
    
    @Override
    protected Object resolveObject(Object o) throws IOException {
        if (o instanceof RemoteObject) {
            RemoteObject remote = (RemoteObject) o;
            return stubFactory.getStub(remote, client);
        }
        
        return o;
    }
    
}
